package com.letu.core.utils;

import com.letu.core.context.ContextUtil;

import java.util.HashMap;
import java.util.Map;

public class HeaderUtil {
    public static Map<String, Object> getHeaderMap() {
        Map<String, Object> headerMap = new HashMap<>();
        //全局变量组装
        headerMap.put("userId", ContextUtil.getUserId());
        headerMap.put("gameTag", ContextUtil.getGameTag());
        headerMap.put("name", ContextUtil.getName());
        headerMap.put("trace", ContextUtil.getTrace());
        headerMap.put("terminalType", ContextUtil.getTerminalType());
        headerMap.put("x-feign", ContextUtil.getXFeign());
        return headerMap;
    }


    public static void parseHeaderMap(Map<String, Object> headerMap) {
        if (headerMap == null) {
            return;
        }
        ContextUtil.setUserId(headerMap.get("userId") == null ? null : Long.parseLong(headerMap.get("userId").toString()));
        ContextUtil.setName(headerMap.get("name") == null ? null : (String) headerMap.get("name"));
        ContextUtil.setTrace(headerMap.get("trace") == null ? null : (String) headerMap.get("trace"));
        ContextUtil.setTerminalType(headerMap.get("terminalType") == null ? null : (String) headerMap.get("terminalType"));
        ContextUtil.setXFeign(headerMap.get("x-feign") == null ? null : (String) headerMap.get("x-feign"));
    }
}
